package com.suxin.chain.call;

import com.suxin.chain.ContractChain;
import com.suxin.chain.Interceptor.Interceptor;
import com.suxin.chain.domain.ContractRequest;
import com.suxin.chain.domain.ContractResponse;

import java.util.List;

/**
 * @Author: tang
 * @Description:
 * @Date 2024/6/20 10:22
 */
public class ContractCall<T extends ContractRequest> implements Call<T,ContractResponse>{

    private final T originalRequest;

    private final List<Interceptor<T, ContractResponse>> interceptors;

    public ContractCall(T originalRequest, List<Interceptor<T, ContractResponse>> interceptors) {
        this.originalRequest = originalRequest;
        this.interceptors = interceptors;
    }


    @Override
    public ContractResponse exectue() {
        ContractChain<T> chain = new ContractChain<>(0, interceptors, originalRequest);
        return chain.proceed(request());
    }

    @Override
    public T request() {
        return originalRequest;
    }
}